package com.woniuxy.cloud.areaassembly.mapper;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.woniuxy.cloud.areaassembly.entity.SysArea;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * Mapper 接口
 * </p>
 *
 * @author 周川雄
 * @since 2022-02-18
 */
public interface SysAreaMapper extends BaseMapper<SysArea> {
    @Select(" SELECT * FROM(" +
            "SELECT * FROM sys_area WHERE id = #{areaId}\n" +
            "UNION\n" +
            "\tSELECT t2.* FROM `sys_area` t1\n" +
            "\tJOIN `sys_area` t2 ON t1.id = t2.area_parent_id\n" +
            "\tWHERE t1.area_parent_id = #{areaId} OR t1.id = #{areaId}" +
            " ) a    ${ew.customSqlSegment}")
    List<SysArea> selectAreaLevel1(@Param("areaId") Integer areaId, @Param(Constants.WRAPPER) QueryWrapper<SysArea> queryWrapper);

    @Select(" SELECT * FROM(   SELECT * FROM sys_area WHERE id =  #{areaId}\n" +
            "    UNION\n" +
            "    SELECT * FROM sys_area WHERE area_parent_id =  #{areaId}  ) a   ${ew.customSqlSegment}")
    List<SysArea> selectAreaLevel2(@Param("areaId") Integer areaId, @Param(Constants.WRAPPER) QueryWrapper<SysArea> queryWrapper);


}
